﻿//#include"inherit-test.h"
//#include"polymorphism-test.h"
//int main()
//{
//	//test1();
//	sherry::test1();
//	return 0;
//}
#include<math.h>
//---子程序1(计算模型体的理论函数值)---//
void XASU(double* x, double* fun, double* xk, double* zk, int n)
{
	double piz = 1.0 / (2 * 3.141592635);
	double aa, bb, cc, dd, a, b, c, d, e, f, g, h, u, a1, a2, b1, b2, v, w;
	int k;
	aa = sin(x[4] * pi);
	bb = cos(x[4] * pi);
	cc = sin(x[5] * pi);
	dd = cos(x[5] * pi);
	for (k = 0; k < n; k++)
	{
		a = x[1] - zk[k] + x[3] * aa / 2.0;
		b = x[1] - zk[k] - x[3] * aa / 2.0;
		c = xk[k] - x[0] + x[3] * bb / 2.0;
		d = xk[k] - x[0] - x[3] * bb / 2.0;
		e = c + x[2] / 2.0;
		f = c - x[2] / 2.0;
		g = d + x[2] / 2.0;
		h = d - x[2] / 2.0;
		u = (b * b + f * f) * (a * a + g * g) / (b * b + e * e) / (a * a + h * h);
		a2 = b * b + c * c - x[2] * x[2] / 4.0;
		b2 = x[2] * b;
		QSAT(a2, b2, &v); //子程序5调用//
		a1 = a * a + d * d - x[2] * x[2] / 4.0;
		b1 = x[2] * a;
		QSAT(a1, b1, &w); //子程序5调用//
		u = log(u);
		fun[k] = piz * x[6] * aa * ((dd * aa - cc * bb) / 2.0 * u + (dd * bb + cc * aa) * (v￾w));
	}
}

void TEDU(double* x, double jac[][8], double
	* fun, double* funo, double* xk, double* zk, int n, int m)
{
	int k, i;
	/* FILE* fp;
	fp = fopen ("222.dat", "w");*/
	for (i = 0; i < m; i++) //--circle 20--//
	{
		x[i] = x[i] + 0.1;
		XASU(x, funo, xk, zk, n); //子程序1调用//
		for (k = 0; k < n; k++) //--circle 25--//
		{
			// fprintf(fp, "funo[%d]=%lf fun[% d] = % lf\n", k, funo[k],k, fun[k]);
				jac[k][i] = (funo[k] - fun[k]) / 0.1;
		}
		x[i] = x[i] - 0.1;
	}
	// fclose(fp);
}

double QF(double* g, double
	* dg, double b, double* fun, int n)
{
	double f;
	f = 0.0;
	int k;
	for (k = 0; k < n; k++) //--circle 30---
	//
	{
		dg[k] = g[k] - fun[k] - b;
		f += dg[k] * dg[k];
	}
	returnf;
}